home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgramD2.iso
/
Borland
/
Borland C++ V5.02
/
APPEXPRT.PAK
/
TMDICLIE.OWL
< prev
next >
Wrap
Text File
|
1997-05-06
|
18KB
|
576 lines
'----------------------------------------------------------------------------
' Expert - (C) Copyright 1993, 1995 by Borland International, Inc.
' All Rights Reserved.
'
' SUBSYSTEM: OWL code template
' FILE: TMDIClient.OWL
'
'
' OVERVIEW
' ~~~~~~~~
' Definition of all OWL classes when can be generated by the CODEGEN phase of
' AppGen and ClassExpert. AppGen generates when all options have been selected
' and multiple classes are generated. ClassExpert uses the CODEGEN phase when
' a new class is generated.
'----------------------------------------------------------------------------
<<[H]TMDIClient [[TMDIClient]]
##{hheader.snp}
##<<TApplication QUERY_FILENAME_CPP [[FileName]]
#include "[[FileName]].rh" // Definition of all resources.
//{{TMDIClient = [[TMDIClient]]}}
class [[TMDIClient]] : public TMDIClient {
public:
int ChildCount; // Number of child window created.
[[TMDIClient]](TModule* module = 0);
virtual ~[[TMDIClient]]();
void OpenFile(const char* fileName = 0);
##--BEGIN-- !@OPT_APPL_DOCVIEW
##<<TMDIChild QUERY_CLASS_NAME [[ClientClass]]
##<<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##BaseClient == "TListBox" 3
private:
void LoadTextFile();
##--END-- !@OPT_APPL_DOCVIEW
//{{[[TMDIClient]]VIRTUAL_BEGIN}}
protected:
##:DBVirtual(\\"[[TMDIClient]]", "SetupWindow")
virtual void SetupWindow();
//{{[[TMDIClient]]VIRTUAL_END}}
//{{[[TMDIClient]]RSP_TBL_BEGIN}}
protected:
##!@OPT_APPL_DOCVIEW 3
void CmFileNew();
void CmFileOpen();
void CmFileClose();
##@OPT_APPL_PRINTING 4
void CmFilePrint();
void CmFilePrintSetup();
void CmFilePrintPreview();
void CmPrintEnable(TCommandEnabler& tce);
##@OPT_APPL_DRAGDROP
void EvDropFiles(TDropInfo);
//{{[[TMDIClient]]RSP_TBL_END}}
DECLARE_RESPONSE_TABLE([[TMDIClient]]);
}; //{{[[TMDIClient]]}}
##{hfooter.snp}
>>[H]TMDIClient
'
' TMDIClient CPP file.
'
<<[CPP]TMDIClient [[TMDIClient]]
##{cheader.snp}
#include <owl/pch.h>
##@OPT_APPL_PRINTING && @OPT_APPL_DOCVIEW
#include <owl/docmanag.h>
#include <owl/listbox.h>
#include <stdio.h>
##<<TApplication QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
##--BEGIN-- !@OPT_APPL_DOCVIEW
## --BEGIN-- @QUERY_APPL_MODEL == VALUE_MDI
##: <<TMDIChild QUERY_WIND_CLIENT [[Client]]
##: <<*Client QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
## --END-- @QUERY_APPL_MODEL == VALUE_MDI
##--END-- !@OPT_APPL_DOCVIEW
##<<TMDIChild QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
##QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
##@OPT_APPL_PRINTING 2
#include "apxprint.h"
#include "apxprev.h"
//{{[[TMDIClient]] Implementation}}
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 4
//
// Build a response table for all messages/commands handled
// by [[TMDIClient]] derived from TMDIClient.
//
DEFINE_RESPONSE_TABLE1([[TMDIClient]], TMDIClient)
//{{[[TMDIClient]]RSP_TBL_BEGIN}}
##!@OPT_APPL_DOCVIEW 3
##:DBResponse(\\"[[TMDIClient]]", "CM_MDIFILENEW", "CmFileNew", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_MDIFILEOPEN", "CmFileOpen", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILECLOSE", "CmFileClose", "", "COMMAND")
EV_COMMAND(CM_MDIFILENEW, CmFileNew),
EV_COMMAND(CM_MDIFILEOPEN, CmFileOpen),
EV_COMMAND(CM_FILECLOSE, CmFileClose),
##@OPT_APPL_PRINTING 6
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINT", "CmFilePrint", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTERSETUP", "CmFilePrintSetup", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTPREVIEW", "CmFilePrintPreview", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINT", "CmPrintEnable", "", "ENABLER")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTERSETUP", "CmPrintEnable", "", "ENABLER")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTPREVIEW", "CmPrintEnable", "", "ENABLER")
EV_COMMAND(CM_FILEPRINT, CmFilePrint),
EV_COMMAND(CM_FILEPRINTERSETUP, CmFilePrintSetup),
EV_COMMAND(CM_FILEPRINTPREVIEW, CmFilePrintPreview),
EV_COMMAND_ENABLE(CM_FILEPRINT, CmPrintEnable),
EV_COMMAND_ENABLE(CM_FILEPRINTERSETUP, CmPrintEnable),
EV_COMMAND_ENABLE(CM_FILEPRINTPREVIEW, CmPrintEnable),
##@OPT_APPL_DRAGDROP
##:DBResponse(\\"[[TMDIClient]]", "", "", "WM_DROPFILES", "")
EV_WM_DROPFILES,
//{{[[TMDIClient]]RSP_TBL_END}}
END_RESPONSE_TABLE;
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~~
// Construction/Destruction handling.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
[[TMDIClient]]::[[TMDIClient]](TModule* module)
:
TMDIClient(module)
{
##QUERY_WIND_STYLE [[StyleAttributes]]
##StyleAttributes != "" 3
// Override the default window style for TMDIClient.
[[StyleAttributes]]
##{wndbkgd.snp}
ChildCount = 0;
// INSERT>> Your constructor code here.
}
[[TMDIClient]]::~[[TMDIClient]]()
{
Destroy();
// INSERT>> Your destructor code here.
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~~
// MDIClient site initialization.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::SetupWindow()
{
// Default SetUpWindow processing.
//
TMDIClient::SetupWindow();
##--BEGIN-- !@OPT_APPL_DOCVIEW
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 3
// Common file file flags and filters for Open/Save As dialogs. Filename and directory are
// computed in the member functions CmFileOpen, and CmFileSaveAs.
//
theApp->FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
##OPT_DV_RESET
##OPT_DV_NEXT
##QUERY_DV_DESCR [[Descr]]
##--BEGIN-- QUERY_DV_FILTER [[Filter]]
## (Filter != "*.*") || (Descr != "All Files")
theApp->FileData.SetFilter("[[Descr]] ([[Filter]])|[[Filter]]|All Files (*.*)|*.*|");
## (Filter == "*.*") && (Descr == "All Files")
theApp->FileData.SetFilter("All Files (*.*)|*.*|");
##QUERY_DV_EXT [[Ext]]
theApp->FileData.DefExt = "[[Ext]]";
##--END-- QUERY_DV_FILTER [[Filter]]
##--END-- !@OPT_APPL_DOCVIEW
##@OPT_APPL_DRAGDROP 3
// Accept files via drag/drop in the client window.
//
DragAcceptFiles(true);
}
##--BEGIN-- !@OPT_APPL_DOCVIEW
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~~
// Menu File New command
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFileNew()
{
##<<TMDIChild QUERY_WIND_CLIENT [[ClientClass]]
##--BEGIN-- <<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##--BEGIN-- BaseClient != "TEditFile"
TAPointer<char> title = new char[255];
TAPointer<char> numberStr = new char[16];
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Generate a title for the MDI child window.
//
if (GetModule()->LoadString(IDS_UNTITLED, title, sizeof title)) {
sprintf(numberStr, " - %d", ++ChildCount);
strcat(title, numberStr);
}
else
title[0] = '\0';
##--END-- BaseClient != "TEditFile"
##--BEGIN-- BaseClient == "TEditFile"
TAPointer<char> title = new char[255];
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Generate a title for the MDI child window.
//
sprintf(title, "%d", ++ChildCount);
##--END-- BaseClient "TEditFile"
##--BEGIN-- <<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
##BaseClient == "TEditFile"
[[TMDIChild]]* child = new [[TMDIChild]](*this, title, 0);
##BaseClient == "TListBox"
[[TMDIChild]]* child = new [[TMDIChild]](*this, title, 0);
##BaseClient == "TWindow"
[[TMDIChild]]* child = new [[TMDIChild]](*this, title, 0);
##--END-- <<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
##--END-- <<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Assign icons for this child window.
//
child->SetIcon(GetApplication(), IDI_DOC);
child->SetIconSm(GetApplication(), IDI_DOC);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// If the current active MDI child is maximize then this one should be also.
//
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
[[TMDIChild]]* curChild = ([[TMDIChild]] *)GetActiveMDIChild();
if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
child->Attr.Style |= WS_MAXIMIZE;
child->Create();
}
void [[TMDIClient]]::OpenFile(const char* fileName)
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (fileName)
strcpy(theApp->FileData.FileName, fileName);
##<<TMDIChild QUERY_WIND_CLIENT [[TMDIChildClient]]
// Create a MDIChild window whose client is [[TMDIChildClient]].
//
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
##<<TMDIChild QUERY_WIND_CLIENT [[ClientClass]]
##<<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##--BEGIN-- TRUE
##BaseClient == "TEditFile"
[[TMDIChild]]* child = new [[TMDIChild]](*this, "", new [[ClientClass]](0, 0, 0, 0, 0, 0, 0, theApp->FileData.FileName));
##BaseClient == "TListBox" 2
[[ClientClass]] far* client = new [[ClientClass]](0, 0, 0, 0, 100, 100);
[[TMDIChild]]* child = new [[TMDIChild]](*this, theApp->FileData.FileName, client);
##BaseClient == "TWindow"
[[TMDIChild]]* child = new [[TMDIChild]](*this, theApp->FileData.FileName, new [[ClientClass]](0));
##--END-- TRUE
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Assign icons for this child window.
//
child->SetIcon(GetApplication(), IDI_DOC);
child->SetIconSm(GetApplication(), IDI_DOC);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// If the current active MDI child is maximize then this one should be also.
//
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
[[TMDIChild]]* curChild = ([[TMDIChild]] *)GetActiveMDIChild();
if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
child->Attr.Style |= WS_MAXIMIZE;
child->Create();
##--BEGIN-- !@OPT_APPL_DOCVIEW
##<<TMDIChild QUERY_CLASS_NAME [[ClientClass]]
##<<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##BaseClient == "TListBox" 2
LoadTextFile();
##--END-- !@OPT_APPL_DOCVIEW
##--BEGIN-- @OPT_APPL_MRU
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Add the file to the MRU list.
//
theApp->SaveMenuChoice(theApp->FileData.FileName);
##--END-- @OPT_APPL_MRU
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~~
// Menu File Open command
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFileOpen()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Display standard Open dialog box to select a file name.
//
*(theApp->FileData.FileName) = 0;
if (TFileOpenDialog(this, theApp->FileData).Execute() == IDOK)
OpenFile();
}
##<<TMDIChild QUERY_CLASS_NAME [[ClientClass]]
##<<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##--BEGIN-- BaseClient == "TListBox"
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Used by ListBox client to read a text file into the list box.
//
void [[TMDIClient]]::LoadTextFile()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
[[TMDIChild]]* curChild = ([[TMDIChild]] *)GetActiveMDIChild();
TListBox* client = TYPESAFE_DOWNCAST(curChild->GetClientWindow(), TListBox);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Only work if the client class is a TListBox.
//
if (client) {
ifstream inStream(theApp->FileData.FileName);
TAPointer<char> buf = new char[255+1];
client->ClearList();
while (inStream.good()) {
inStream.getline(buf, 255);
if (inStream.good())
client->AddString(buf);
}
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Return an error message if we had a stream error and it wasn't the eof.
//
if (inStream.bad() && !inStream.eof()) {
string msgTemplate(*GetModule(), IDS_UNABLEREAD);
char* msg = new char[_MAX_PATH + msgTemplate.length()];
sprintf(msg, msgTemplate.c_str(), *theApp->FileData.FileName);
MessageBox(msg, GetApplication()->GetName(), MB_ICONEXCLAMATION | MB_OK);
delete msg;
}
}
}
##--END-- BaseClient == "TListBox"
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~~
// Menu File Close command
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFileClose()
{
##<<TMDIChild QUERY_CLASS_NAME [[ClientClass]]
[[ClientClass]]* curChild = ([[ClientClass]] *)GetActiveMDIChild();
if (curChild) {
curChild->CloseWindow();
}
}
##--END-- !@OPT_APPL_DOCVIEW
##--BEGIN-- @OPT_APPL_PRINTING
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~
// Menu File Print command
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFilePrint()
{
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Create Printer object if not already created.
//
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
if (!theApp->Printer)
theApp->Printer = new TPrinter(theApp);
TAPointer<char> docName = new char[_MAX_PATH];
##--BEGIN-- @OPT_APPL_DOCVIEW
TDocument* currentDoc = theApp->GetDocManager()->GetCurrentDoc();
if (currentDoc->GetTitle())
strcpy(docName, currentDoc->GetTitle());
else
strcpy(docName, "Document");
##--END-- @OPT_APPL_DOCVIEW
##!@OPT_APPL_DOCVIEW 2
GetActiveMDIChild()->GetWindowText(docName, _MAX_PATH);
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Create Printout window and set characteristics.
//
TApxPrintout printout(theApp->Printer, docName, GetActiveMDIChild()->GetClientWindow(), true);
theApp->Printing++;
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Bring up the Print dialog and print the document.
//
theApp->Printer->Print(GetWindowPtr(GetActiveWindow()), printout, true);
theApp->Printing--;
}
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~
// Menu File Print Setup command
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFilePrintSetup()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
if (!theApp->Printer)
theApp->Printer = new TPrinter(theApp);
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Bring up the Print Setup dialog.
//
theApp->Printer->Setup(this);
}
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~
// Menu File Print Preview command
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFilePrintPreview()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
if (!theApp->Printer)
theApp->Printer = new TPrinter(GetApplication());
theApp->Printing++;
TApxPreviewWin* prevW = new TApxPreviewWin(Parent, theApp->Printer, GetActiveMDIChild()->GetClientWindow(), "Print Preview", new TLayoutWindow(0));
prevW->Create();
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 3
// Here we resize the preview window to take the size of the MainWindow, then
// hide the MainWindow.
//
TFrameWindow * mainWindow = GetApplication()->GetMainWindow();
TRect r = mainWindow->GetWindowRect();
prevW->MoveWindow(r);
prevW->ShowWindow(SW_SHOWNORMAL);
mainWindow->ShowWindow(SW_HIDE);
GetApplication()->BeginModal(GetApplication()->GetMainWindow());
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 3
// After the user closes the preview Window, we take its size and use it
// to size the MainWindow, then show the MainWindow again.
//
r = prevW->GetWindowRect();
mainWindow->MoveWindow(r);
mainWindow->ShowWindow(SW_SHOWNORMAL);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 3
// We must destroy the preview window explicitly. Otherwise, the window will
// not be destroyed until it's parent the MainWindow is destroyed.
//
prevW->Destroy();
delete prevW;
theApp->Printing--;
}
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//--------------------------------------------------------
// [[TMDIClient]]
// ~~~~~~~~~~
// Menu enabler used by Print, Print Setup and Print Preview.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmPrintEnable(TCommandEnabler& tce)
{
if (GetActiveMDIChild()) {
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 4
// If we have a Printer already created just test if all is okay.
// Otherwise create a Printer object and make sure the printer really
// exists and then delete the Printer object.
//
if (!theApp->Printer) {
theApp->Printer = new TPrinter(theApp);
tce.Enable(!theApp->Printer->GetSetup().Error);
}
else
tce.Enable(!theApp->Printer->GetSetup().Error);
}
}
else
tce.Enable(false);
}
##--END-- @OPT_APPL_PRINTING
##--BEGIN-- @OPT_APPL_DRAGDROP
void [[TMDIClient]]::EvDropFiles(TDropInfo)
{
Parent->ForwardMessage();
}
##--END-- @OPT_APPL_DRAGDROP
>>[CPP]TMDIClient